<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/mui.picker.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/mui.poppicker.css" />
		<style>
		.select{line-height:40px;width:56%;display: inline-block;height: 40px;
			text-overflow: ellipsis;
		    white-space: nowrap;
		    overflow: hidden;float: left;
		}
		.qbs .mui-icon{float: left;margin:8px 0;color: #666;}
		* .mui-input-row{
			font-size: 16px;
		}
		.ziti{
			color: #555;
		}
		input::-webkit-input-placeholder { 
			color: #888;
		}
		.register{
			display: block;
			width: 90vw;
			height: 12vw;
			line-height: 12vw;
			text-align: center;
			color: #fff;
			margin:0 5vw;
			margin-top: 8vw;
			background: #004a86;
			border-radius: 2vw;
			font-size: 1.3rem;
		}
		</style>
	</head>
	
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">新用户请选择</h1>
		</header>
		
		<div class="mui-content">
			<div class="mui-input-group">
				<div class="mui-input-row">
					<label>工号</label>
					<input type="text" id="input1" class="mui-input-clear ziti" placeholder="" maxlength="45" disabled>
				</div>
				<div class="mui-input-row">
					<label>姓名</label>
					<input type="text" id="input2" class="mui-input-clear ziti" placeholder="" maxlength="45" disabled>
				</div>
				<div class="mui-input-row">
					<label>手机<font color="red"> *</font></label>
					<input type="text" id="phone" class="mui-input-clear ziti" placeholder="请输入手机号码" maxlength="45" disabled>
				</div>
				<div class="mui-input-row qbs">
					<label>区域<font color="red"> *</font></label>
					<span class="select ziti" id="quyu">请选择</span><i class="mui-icon mui-icon-arrowright"></i>
				</div>
				<div class="mui-input-row qbs">
					<label>场站<font color="red"> *</font></label>
					<span class="select ziti" id="fengchang">请选择</span><i class="mui-icon mui-icon-arrowright"></i>
				</div>
			</div>
			<span class="register" id="submit">确认</span>
		</div>
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/mui.picker.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/mui.poppicker.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/jquery-3.2.1.min.js"></script>
		<script src="../js/mkeyplus.base.js"></script>
		<script src="../../../js/common.js"></script>
		
		<script src="../group/js/internalApp4Alogin.js"></script>
		
		<script>
		var user = JSON.parse(localStorage.getItem('groupUser'))
		var areaPick = new mui.PopPicker();
		var windPick = new mui.PopPicker();
		var areaData = []
		var windData = []
		var bCg = JSON.parse(localStorage.getItem('baseConfig'))
		var form = {
			username:user.userName,
			name:user.realName,
			password:'Deepen@201410',
			phoneno:user.phone,
			neibu:'1',
			unit:'',
			orgid:'',
			desc:''
		}
		
		mui.init();
		mui.plusReady(function() {
			document.getElementById('input1').value = form.username
			document.getElementById('input2').value = form.name
			document.getElementById('phone').value = form.phoneno
			getOrg()
		});
		function submit(){
			form.phoneno = document.getElementById('phone').value
			var phoneReg = /^1[0-9]{10}$/;
			//手机
			if(form.phoneno == "") {
				mui.toast('请输入手机号码!');
				return;
			}
			if(!phoneReg.test(form.phoneno)) {
				mui.toast('请输入正确的手机号码!');
				return;
			}
			if(!form.orgid){
				mui.toast('请选择区域和场站!');
				return;
			}
			plus.nativeUI.showWaiting('注册中...');
			var C = bCg
						mui.baseWApp.httpRequst(C.protocol+C.host+C.XJ_path+'/api/v2/users/regist', form, function(data) {
							plus.nativeUI.closeWaiting();
							console.log(JSON.stringify(data));
							if(data.status == '200') {
			//					submitInfoxj();
									mui.toast('注册成功!');
									child4Alogin.jiankong(C.protocol+C.host+C.XJ_path);
							} else if(data.status == '400') {
								plus.nativeUI.closeWaiting();
								mui.toast('没有选择组织orgid!');
							} else if(data.status == '409') {
								plus.nativeUI.closeWaiting();
								mui.toast('该用户名已存在!');
							} else if(data.status == "500") {
								plus.nativeUI.closeWaiting();
								mui.toast('注册失败,请检查网络!');
							}
						}, function() {
							plus.nativeUI.closeWaiting();
							//				console.log("注册失败");
							//				mui.toast("注册失败！！！");
						});
			

		}
		function getOrg() {
			//plus.nativeUI.showWaiting('获取区域信息中...');
			var C = bCg
			mui.baseWApp.httpRequst(C.protocol+C.host+C.XJ_path+'/api/v2/users/getOrgs', {},
				function(data) {
					if(data.status == 200) {
						console.log("获取区域信息成功");
						orgData = data.data;
						areaData = new Array(); //区域数据
						$.each(orgData, function(i, v) {
							var temp = {
								value: v.id,
								text: v.name
							}
							areaData.push(temp);
						});
						areaPick.setData(areaData);
					} else if(data.status == "500") {
						console.log('获取区域信息失败!')
						console.log(JSON.stringify(data))
					}
				},
				function() {
					console.log("获取区域信息失败");
					//mui.toast("获取区域信息失败！！！");
				},'get');
		}
				//选择区域
				document.getElementById('quyu').addEventListener('tap', function() {
		
					areaPick.show(function() {
						var index = areaPick.pickers[0].getSelectedIndex();
						console.log(areaPick.pickers[0].getSelectedIndex());
						//设置显示值
						document.getElementById('quyu').textContent = areaData[index].text;
						$('#quyu').attr('data-id', areaData[index].value);
						//设置风场值
						windData = new Array();
						document.getElementById('fengchang').textContent = "请选择";
						form.orgid = ''
						$.each(orgData[index].child, function(i, v) {
		
							var temp = {
								value: v.id,
								text: v.name
							}
							windData.push(temp);
						});
						windPick.setData(windData);
					});
		
				});
						//选择风场
						document.getElementById('fengchang').addEventListener('tap', function() {
				
							windPick.show(function(selectItems) {
								document.getElementById('fengchang').textContent = windData[windPick.pickers[0].getSelectedIndex()].text;
								$('#fengchang').attr('data-id', windData[windPick.pickers[0].getSelectedIndex()].value);
								console.log('org-id===' + windData[windPick.pickers[0].getSelectedIndex()].value);
								form.orgid = windData[windPick.pickers[0].getSelectedIndex()].value
							});
				
						});
document.getElementById('submit').addEventListener('tap', function() {
	return submit()
})
		</script>
	</body>

</html>